public RasterRegion(
byte[] data
)
public RasterRegion(
byte[] data
);
public:
RasterRegion(
array<byte>^ data
)
__init__(self,data) # Overloaded constructor
data
An array of Byte that defines the interior of the new RasterRegion
You can get the data that defines a region by creating a RasterRegion using any of the region methods and using the GetData method to obtain the data.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
public void RasterRegionDataExample()
{
string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");
string destFileName1 = Path.Combine(LEAD_VARS.ImagesDir, "Image1_WithRegion1.bmp");
string regionFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_Region.bin");
string destFileName2 = Path.Combine(LEAD_VARS.ImagesDir, "Image1_WithRegion2.bmp");
RasterRegion region = null;
using (RasterCodecs codecs = new RasterCodecs())
{
// Load the source image
using (RasterImage image = codecs.Load(srcFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1))
{
// Add an elliptical region to it
image.AddEllipseToRegion(null, new LeadRect(0, 0, image.ImageWidth, image.ImageHeight), RasterRegionCombineMode.Set);
// Fill the image with a color and save it to disk to show the region
FillCommand cmd = new FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Yellow));
cmd.Run(image);
codecs.Save(image, destFileName1, RasterImageFormat.Bmp, 24);
// Get the region
region = image.GetRegion(null);
}
// Save this region to disk
byte[] data = region.GetData();
File.WriteAllBytes(regionFileName, data);
// Dispose the region
region.Dispose();
// Now, reload the image and region from disk, set the region into the image directly
// from the data we save, re-fill and save again
using (RasterImage image = codecs.Load(srcFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1))
{
// Create a region from the data we saved on disk
data = File.ReadAllBytes(regionFileName);
using (region = new RasterRegion(data))
{
// Set this region into the image
image.SetRegion(null, region, RasterRegionCombineMode.Set);
}
// Fill the image with a color and save it to disk to show the region
FillCommand cmd = new FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Yellow));
cmd.Run(image);
codecs.Save(image, destFileName2, RasterImageFormat.Bmp, 24);
}
}
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images";
}
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.junit.*;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import leadtools.*;
import leadtools.codecs.*;
import leadtools.imageprocessing.FillCommand;
public void rasterRegionDataExample() throws IOException {
final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images";
String srcFileName = combine(LEAD_VARS_IMAGES_DIR, "Image1.cmp");
String destFileName1 = combine(LEAD_VARS_IMAGES_DIR, "Image1_WithRegion1.bmp");
String regionFileName = combine(LEAD_VARS_IMAGES_DIR, "Image1_Region.bin");
String destFileName2 = combine(LEAD_VARS_IMAGES_DIR, "Image1_WithRegion2.bmp");
RasterRegion region = null;
RasterCodecs codecs = new RasterCodecs();
// Load the source image
RasterImage image = codecs.load(srcFileName, 0, CodecsLoadByteOrder.BGR_OR_GRAY, 1, 1);
// Add an elliptical region to it
image.addEllipseToRegion(null, new LeadRect(0, 0, image.getImageWidth(), image.getImageHeight()),
RasterRegionCombineMode.SET);
// Fill the image with a color and save it to disk to show the region
FillCommand cmd = new FillCommand(RasterColor.fromKnownColor(RasterKnownColor.YELLOW));
cmd.run(image);
codecs.save(image, destFileName1, RasterImageFormat.BMP, 24);
// Get the region
region = image.getRegion(null);
// Save this region to disk
byte[] data = region.getData();
try (FileOutputStream fos = new FileOutputStream(regionFileName)) {
fos.write(data);
}
// Dispose the region
region.dispose();
// Now, reload the image and region from disk, set the region into the image
// directly
// from the data we save, re-fill and save again
RasterImage image2 = codecs.load(srcFileName, 0, CodecsLoadByteOrder.BGR_OR_GRAY, 1, 1);
// Create a region from the data we saved on disk
data = Files.readAllBytes(Paths.get(regionFileName));
// Set this region into the image
image2.setRegion(null, region, RasterRegionCombineMode.SET);
// Fill the image with a color and save it to disk to show the region
FillCommand cmd2 = new FillCommand(RasterColor.fromKnownColor(RasterKnownColor.YELLOW));
cmd2.run(image);
codecs.save(image2, destFileName2, RasterImageFormat.BMP, 24);
assertTrue("Image 1 unsuccessfully saved", new File(destFileName1).exists());
System.out.println("Command run and image saved to " + destFileName1);
assertTrue("Image 2 unsuccessfully saved", new File(destFileName2).exists());
System.out.println("Command run and image saved to " + destFileName2);
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document